﻿using BlockeyEssentials;
using BlockeyEssentials.Drawing;
using BlockeyEssentials.ScreenSystem;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using BlockeyEssentials.ScreenSystem.ScreenTypes;
using BlockeyEssentials.Input;
using Microsoft.Xna.Framework.Input;
using Blockey.ScreenManagers;

namespace Blockey.MenuSystemScreens
{
    public class TeamSelectScreen : Screen
    {
        public TeamSelectScreen(ScreenManager oManager)
            : base(oManager)
        {
            _GoToGame = false;

            var oWidth = 900;
            int oBuffer = 60;
            int oInsideBuffer = 20;

            var oBounds = new Rectangle(
                All.Resolution.Center.X - (oWidth / 2) - oInsideBuffer,
                oBuffer,
                oWidth,
                All.Resolution.Height - (oBuffer * 2));

            var oMenuWidth = 300;

            var oShape = new Rectangle(
                oBounds.Center.X - (oMenuWidth / 2), 
                oBounds.Top, 
                oMenuWidth, 
                oBounds.Height);

            //-------- Menu Area --------//
            _MenuAreaSprite = new SpriteR(All.Texture_Square, oShape);
            _MenuAreaSprite.Color = Color.Black;
            _MenuAreaSprite.Layer = 80;

            //-------- Home Logo Area --------//
            oShape.X = oBounds.Left;
            oShape.Width = _MenuAreaSprite.Rectangle.Left - oInsideBuffer - oBounds.Left;
            oShape.Height = oShape.Width;
            _HomeLogoAreaSprite = new SpriteR(All.Texture_Square, oShape);
            _HomeLogoAreaSprite.Color = Color.Red;
            _HomeLogoAreaSprite.Layer = 80;

            //-------- Away Logo Area --------//
            oShape.X = _MenuAreaSprite.Rectangle.Right + oInsideBuffer;
            _AwayLogoAreaSprite = new SpriteR(All.Texture_Square, oShape);
            _AwayLogoAreaSprite.Color = Color.Blue;
            _AwayLogoAreaSprite.Layer = 80;

            //-------- Home Team Area --------//
            oShape.X = oBounds.Left;
            oShape.Height = oBounds.Bottom - _HomeLogoAreaSprite.Rectangle.Bottom - oInsideBuffer;
            oShape.Y = _HomeLogoAreaSprite.Rectangle.Bottom + oInsideBuffer;
            _HomeTeamAreaSprite = new SpriteR(All.Texture_Square, oShape);
            _HomeTeamAreaSprite.Color = Color.IndianRed;
            _HomeTeamAreaSprite.Layer = 80;

            //-------- Away Team Area --------//
            oShape.X = _MenuAreaSprite.Rectangle.Right + oInsideBuffer;
            _AwayTeamAreaSprite = new SpriteR(All.Texture_Square, oShape);
            _AwayTeamAreaSprite.Color = Color.BlueViolet;
            _AwayTeamAreaSprite.Layer = 80;
        }

        #region Methods

        public override void Update()
        {
            if (Active)
            {
                Input();
            }
        }

        public override void Draw(SpriteBatch oSB)
        {
            _MenuAreaSprite.Draw(oSB, Transition);
            _HomeLogoAreaSprite.Draw(oSB, Transition);
            _AwayLogoAreaSprite.Draw(oSB, Transition);
            _HomeTeamAreaSprite.Draw(oSB, Transition);
            _AwayTeamAreaSprite.Draw(oSB, Transition);
        }

        #region Helper Methods

        private void Input()
        {
            var oInput = InputManager.Keyboard;

            if (oInput.JustPressed(Keys.Enter))
            {
                GoToGame();
            }
        }

        private void GoToGame()
        {
            Remove();
            _DestinationManager = new GameplayManager3D(_Manager.Game);
        }

        #endregion

        #endregion

        private SpriteR _MenuAreaSprite;
        private SpriteR _HomeLogoAreaSprite;
        private SpriteR _AwayLogoAreaSprite;
        private SpriteR _HomeTeamAreaSprite;
        private SpriteR _AwayTeamAreaSprite;

        private bool _GoToGame;
    }
}
